<script>
/* jQuery->validation */
$(document).ready(function(){
    $("#PacientePaso2Form").validate();

    $('#PacienteSeleccionarPor1').click(function(){
        $('#overlayer').hide();
    });        
    $('#PacienteSeleccionarPor2').click(function(){
        $('#overlayer').hide();
    });        
    $('#PacienteMedicoElegido').click(function(){
        $('#overlayer').hide();
    });        
    $('#PacienteEspecialidadElegida').click(function(){
        $('#overlayer').hide();
    });        



<?php 
    if($formEnviado == 1){
?>        
    // Muestra Transicion
    $('#overlayer').html('<img src="/images/loading5.gif" style="margin-top: 7px;" />');
    $('#overlayer').show();

<?php   
    }
?>


    $.ajax({
      url: "/turnos/semanal/<?php echo date("Y",$DiaActual).'/'. date("m",$DiaActual).'/'.date("d",$DiaActual);?>",
      cache: false
    })
    .always(function(data, status, xhr) { 
            //alert('Status: ' + xhr.status + ' - statusText: ' +  + xhr.statusText + ' - readyState: ' +  + xhr.readyState + ' - status:' + status);

            $('#overlayer').html(data);  
            $('#overlayer').fadeIn(100);  
    });

});    

</script>

<style>
	.titulo_solicitar_turno {
		float: left; 
		padding: 6px; 
		margin-top:10px; 
		font-size: 16px; 
		font-weight: normal;
	}
	.titulo_solicitar_turno_nombre{
		padding:6px; 
		margin-top:10px;
		float:right; 
		font-size: 14px; 
		font-weight: normal;
	}
</style>


<div id="titulo_encabezado" style="background: none; border: none;">
	<div class='titulo_solicitar_turno btn btn-large btn-primary disabled'>Solicitar Turno en <?php echo $sessCliente['Cliente']['name'];?></div>
<?php 
    if($sessCliente['Medico']['id']>0){ 

        echo "
            <div class='titulo_solicitar_turno_nombre btn btn-large btn-primary disabled'>
               Dr: ".$sessCliente['Medico']['name']."
            </div>    
        ";

    } 
?> 
</div>
    <div style="padding:6px; margin-top:10px;font-size: 14px; font-weight: normal; display:block; clear:both;">
		<b>Sucursal:</b> <?php echo $Sucursal['Sucursal']['name'];?>
		<br><?php echo $Sucursal['Sucursal']['direccion'];?>
		<br><?php echo $Sucursal['Sucursal']['localidad'];?> - <?php echo $Sucursal['Sucursal']['provincia'];?>
		<br><?php echo $Sucursal['Sucursal']['telefono'];?>
	</div>


    <?php echo $this->Form->create('Paciente', array('url' => array('controller' => 'turnos', 'action' => 'paso2'),'inputDefaults' => array('label' => false,'div' => false))); ?>
    <table width='100%'>
        <tr>
            <td style="text-align:right; vertical-align:middle;font-size:14px;padding-right:10px;width:200px;">Sexo:</td>
            <td>
                <?php echo $this->Form->input( 'cliente_id' , array('value'=>$this->data['Paciente']['cliente_id'] , 'type' => 'hidden')); ?> 
                <?php echo $this->Form->input( 'usuario_id' , array('value'=>$this->data['Paciente']['usuario_id'] , 'type' => 'hidden')); ?>
                <?php echo $this->Form->input( 'paciente_id', array('value'=>$this->data['Paciente']['paciente_id'], 'type' => 'hidden')); ?>
                <?php echo $this->Form->input( 'dia'        , array('value'=>$this->data['Paciente']['dia']        , 'type' => 'hidden')); ?>
                <?php echo $this->Form->input( 'mes'        , array('value'=>$this->data['Paciente']['mes']        , 'type' => 'hidden')); ?>
                <?php echo $this->Form->input( 'ano'        , array('value'=>$this->data['Paciente']['ano']        , 'type' => 'hidden')); ?>
                <?php echo $this->Form->input( 'sexo'       , array('value'=>$this->data['Paciente']['sexo']       , 'type' => 'hidden')); ?>
                <?php echo $this->Form->input( 'email'      , array('value'=>$this->data['Paciente']['email']      , 'type' => 'hidden')); ?>
                <?php echo $this->Form->input( 'telefono'   , array('value'=>$this->data['Paciente']['telefono']   , 'type' => 'hidden')); ?>
                <?php echo $this->Form->input( 'financiador'   , array('value'=>$this->data['Paciente']['financiador']   , 'type' => 'hidden')); ?>
                <?php echo $this->Form->select('sexo'       , $sessCliente['Sexo'] , null, array(
																						'escape'   => false, 
																						'empty'    => false, 
																						'class'    => 'required',
																						'disabled' => 'disabled'
																						)); ?>
            </td>
        </tr>
        <tr>
            <td style="text-align:right; vertical-align:middle;font-size:14px;padding-right:10px;">Email:</td>
            <td>
                <?php echo $this->Form->input('email', array(
													'value'    => $this->data['Paciente']['email'], 
													'type'     => 'text', 
													'style'    => 'width:240px',
													'class'    => 'required email',
													'disabled' => 'disabled'
													)); ?>
                
            </td>
        </tr>

        <tr>
            <td style="text-align:right; vertical-align:middle;font-size:14px;padding-right:10px;">Teléfono:</td>
            <td>
                <?php echo $this->Form->input('telefono', array(
                                                    'value'    => $this->data['Paciente']['telefono'], 
                                                    'type'     => 'text', 
                                                    'style'    => 'width:240px',
                                                    'class'    => 'required',
                                                    'disabled' => 'disabled'
                                                    )); ?>
                
            </td>
        </tr>

        <tr>
            <td style="text-align:right; vertical-align:middle;font-size:14px;padding-right:10px;">Fecha de Nacimiento:</td>
            <td>
            <?php 
                for($i=1;$i<=31;$i++){$dia[$i]=$i;}
                echo $this->Form->select('Paciente.dia', $dia, null, array(
																	'escape'   => false, 
																	'empty'    => false, 
																	'class'    => 'required',
																	'disabled' => 'disabled'
																	));
                echo " / ";
                for($i=1;$i<=12;$i++){$mes[$i]=$i;}
                echo $this->Form->select('mes', $mes, null, array(
															'escape'   => false, 
															'empty'    => false, 
															'class'    => 'required',
															'disabled' => 'disabled' 
															));  
                echo " / ";
                $desde = date("Y",time()) - 110;
                for($i=date("Y",time());$i>$desde;$i--){$ano[$i]=$i;}
                echo $this->Form->select('ano', $ano, null, array(
															'escape'   => false, 
															'empty'    => false, 
															'class'    => 'required',
															'disabled' => 'disabled' 
															));  
                
                  
            ?>
            </td>
        </tr>
        <tr>
            <td style="text-align:right; vertical-align:middle;font-size:14px;padding-right:10px;">Apellidos:</td>
            <td>
                <?php 
                    if ($this->data['Paciente']['nombre']==''){$disable='';} else {$disable='disabled';}
                    echo $this->Form->input('apellido', array(
                                                        'value'    => $this->data['Paciente']['apellido'], 
                                                        'type'     => 'text', 
                                                        'style'    => 'width:240px',
                                                        'class'    => 'required',
                                                        'disabled' => $disable
														)); 
                
                    if ($disable=='disabled'){
                        echo $this->Form->input('apellido',  array(
															'value' => $this->data['Paciente']['apellido'],  
															'type'  => 'hidden'
															)); 
                    }
                ?>
                
            </td>
        </tr>

        <tr>
            <td style="text-align:right; vertical-align:middle;font-size:14px;padding-right:10px;">Nombres:</td>
            <td>
                <?php 
                    echo $this->Form->input('nombre', array(
                                                      'value'    => $this->data['Paciente']['nombre'], 
                                                      'type'     => 'text', 
                                                      'style'    => 'width:240px',
                                                      'class'    => 'required',
                                                      'disabled' => $disable
													  )); 
                    if ($disable=='disabled'){
                        echo $this->Form->input('nombre',  array(
															'value' => $this->data['Paciente']['nombre'],  
															'type'  => 'hidden'
															)); 
                    }

                ?>

                
            </td>
        </tr>
        <tr>
            <td style="text-align:right; vertical-align:middle;font-size:14px;padding-right:10px;">Obra Social:</td>
            <td>
                <?php 
                    echo $this->Form->input('financiador', array(
                                                      'value'    => $this->data['Paciente']['financiador'],                         
                                                      'type'     => 'text', 
                                                      'style'    => 'width:240px',
                                                      'class'    => 'required',
                                                      'disabled' => $disable
                                                      )); 
                    if ($disable=='disabled'){
                        echo $this->Form->input('financiador',  array(
                                                            'value' => $this->data['Paciente']['financiador'],  
                                                            'type'  => 'hidden'
                                                            )); 
                    }
                ?>
            </td>
        </tr>

        <tr><td colspan="2">&nbsp;</td></tr>
        <tr>
            <td style="text-align:right; vertical-align:middle;font-size:14px;padding-right:10px;">Razón de la Visita:</td>
            <td>
            <?php 
                echo $this->Form->select('producto', $sessCliente['Productos'], null, array(
																						'escape' => false, 
																						'empty'  => false, 
																						'class'  => 'required' 
																						));  
            ?>
            </td>
        </tr>
        <tr>
            <td style="text-align:right; padding-top: 3px;font-size:14px;padding-right:10px;">Buscar por:</td>            
            <td>
                <table width="100%">
                    <tr>
                        <td>
                            <?php
								if (!isset($this->data['Paciente']['seleccionar_por'])) {
									$this->data['Paciente']['seleccionar_por'] = 1;
								}
                                $options=array('1'=>'Especialista','2'=>'Especialidad');
								
                                $attributes=array(  'legend'    => false, 
													'separator' => '&nbsp;&nbsp;&nbsp;', 
													'value'     => $this->data['Paciente']['seleccionar_por'],
													'class'     => 'radios',
													'style'     => 'width:10px;'
													);
													
                                echo $this->Form->radio('seleccionar_por', $options, $attributes );
                            ?>
                            <br />
                            <?php
                                if ($this->data['Paciente']['seleccionar_por']==2){ $style = 'display:none;';} else {{ $style = 'display:block;';}}
                                echo "<div id='lista_medicos'  style=\"$style\">"; 
                                echo $this->Form->select('medico_elegido', $sessCliente['SelectMedicos'], null, array(
																												'escape' => false, 
																												'empty'  => false, 
																												'class'  => 'required' 
																												));
                                echo "</div>";  
                            ?>
                            <?php 
                                if ($this->data['Paciente']['seleccionar_por']==1){ $style = 'display:none;';} else {{ $style = 'display:block;';}}
                                echo "<div id='lista_especialidades' style=\"$style\">";
                                
								echo $this->Form->select('especialidad_elegida', $sessCliente['SelectEspecialidades'], null, array(
																															'escape' => false, 
																															'empty'  => false, 
																															'class'  => 'required' 
																															));
                                echo "</div>";  
                            ?>
                        
                        </td>

                        <td style="text-align:right;">
                            <?php
                                $options = array('label' => 'Ver Turnos Disponibles',
												 'name'  => 'buscar_turnos',
												 'style' => 'margin-top:20px;margin-right:10px;',
                                                 'class' => 'btn btn-success'
												 );
												 
                                echo $this->Form->end($options); 
                            ?>
                        </td>                    
                    </tr>
                
                </table>
                                                    
            </td>
        </tr>

   
    </table>

	
	<div id="overlayer" class="grid_8 color" style="display:none"></div>          
    
	
	<?php 
    if (isset($this->data['Paciente']['medico_elegido']) or isset($this->data['Paciente']['especialidad_elegida'])) {
    	if( isset($config_agenda) and count($config_agenda) > 0){
    		echo "<br/>";
//            echo $turnos->semanal(date("Y",$DiaActual), date("m",$DiaActual), date("d",$DiaActual), $this->data['Paciente']['medico_elegido'], $data, $config_agenda, $feriados);

   
       	}else{
    		echo '
    			<div style="padding: 10px 10px;">
    				<h1>Este especialista NO tiene agenda de turnos definida</h1>
    			</div>
    		';
    	}    
        echo "<div id='nuevoturno' title='Asignar Turno'></div>";
    }    
	
    ?>
</div>
<div class="clear"> </div>
<?php //pr($data);?>
<?php //pr($this->data['Paciente']);?>
<?php //pr($sessCliente);?>